home *** CD-ROM | disk | FTP | other *** search
/ Windows 95 Super Collection / Windows 95 Super Collection.iso / win95 / internet / rcp3217 / crcp.c next >
Encoding:
C/C++ Source or Header  |  1995-07-01  |  3.6 KB  |  120 lines

  1. //*********************************************************************
  2. //
  3. //  CRCP.C - Example usage of Winsock RCP32.DLL
  4. //
  5. //
  6. //  Winsock RCP32.DLL Copyright (c) 1994 Denicomp Systems
  7. //
  8. // 
  9. //  Usage:
  10. //
  11. //     CRCP [-r] [-a] [-c] [-h] source dest
  12. //
  13. //  Where:
  14. //     -r   - Recursively copy subdirectories
  15. //     -a   - Perform ASCII end-of-line conversion (CR/LF to LF or vice versa)
  16. //     -c   - Preserve case of filenames when using wildcards or -r
  17. //     -h   - Copy hidden files when using wildcards or -r
  18. //     -s   - Substitute '_' for spaces in filenames
  19. //   source - Source host/file specification
  20. //    dest  - Destination host/file specification
  21. //
  22. //  NOTE: Do not combine options after a hyphen; specify each separately.
  23. //        For example, use "-r -a", not "-ra".
  24. //
  25. //  This program will copy the file specified in source to the destination
  26. //  specified.  Either the source or the destination must contain a host name
  27. //  as part of the filename.  The format is:
  28. //
  29. //    [user@]host:[filespec]
  30. //
  31. //   Where "user" is a user on the "host", "host" is a valid host name, and
  32. //   "filespec" is either a directory, filename, or wildcard pattern.
  33. //
  34. //  The directory containing Winsock RCP32.DLL must be in your PATH or
  35. //  RCP32.DLL must reside in the Windows directory.
  36. //
  37. //*********************************************************************
  38.  
  39. #include <windows.h>
  40. #include <stdio.h>
  41. #include <stdlib.h>
  42. #include <conio.h>
  43. #include <string.h>
  44.  
  45. #include "rcp32.h"
  46.  
  47. char errmsg[256];
  48.  
  49. int main (int argc, char *argv[])
  50. {
  51.     HANDLE hConsole;
  52.     int a, result, rflag = 0, aflag = 0, cflag = 0, hflag = 0, sflag = 0;
  53.  
  54.     // check if Win32s, if so, display notice and terminate
  55.     if( GetVersion() & 0x80000000 && (GetVersion() & 0xFF) ==3)
  56.     {
  57.       MessageBoxA(NULL,
  58.               "This application cannot run on Windows 3.1.\n"
  59.               "This application will now terminate.",
  60.               "CRCP",
  61.               MB_OK | MB_ICONSTOP | MB_SETFOREGROUND );
  62.       return(1);
  63.     }
  64.  
  65.     // Open the current console input buffer
  66.     if ((hConsole = CreateFile("CONOUT$", GENERIC_WRITE | GENERIC_READ,
  67.                                FILE_SHARE_READ | FILE_SHARE_WRITE, 0L,
  68.                    OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL,
  69.                    0L)) == INVALID_HANDLE_VALUE )
  70.     {
  71.       printf("\nError: Unable to open console.\n");
  72.       return(-1);
  73.     }
  74.  
  75.     // Need at least two arguments
  76.     if (argc < 3)
  77.     {
  78.       printf("\nUsage: %s [-r][-a][-c] source dest\n",argv[0]);
  79.       return(-1);
  80.     }
  81.  
  82.     // Examine command line arguments
  83.     for(a = 1; a <= argc; a++)
  84.     {
  85.       if (strcmp(argv[a],"-r") == 0)    // -r: Recursive flag
  86.         rflag = 1;
  87.       else if (strcmp(argv[a],"-a") == 0)    // -a: Ascii flag
  88.              aflag = 1;
  89.       else if (strcmp(argv[a],"-c") == 0)    // -c: Preserve case flag
  90.              cflag = 1;
  91.       else if (strcmp(argv[a],"-h") == 0)    // -h: Copy hidden files
  92.              hflag = 1;
  93.       else if (strcmp(argv[a],"-s") == 0)    // -s: Replace spaces with '_'
  94.              sflag = (int)'_';
  95.       else if (argv[a][0] == '-')        // Others are invalid
  96.            {
  97.          printf("Invalid option: %s\n",argv[a]);
  98.          return(-1);
  99.            }
  100.            else                // Found first filename
  101.          break;
  102.     }
  103.  
  104.     printf("Copying %s to %s\n",argv[a],argv[a+1]);
  105.     result = WinsockRCP2(argv[a],argv[a+1],rflag,aflag,cflag,hflag,sflag,
  106.                  errmsg,sizeof(errmsg));
  107.  
  108.     if (result < 0)
  109.       printf("Remote Copy Was Not Successful.\nError: %d - %s\n", result,
  110.          errmsg);
  111.     else
  112.       if (result == 1)
  113.         printf("Remote Copy Successful\n%d File Copied\n",result);
  114.       else
  115.         printf("Remote Copy Successful\n%d Files Copied\n",result);
  116.  
  117.     return(0);
  118. }
  119.  
  120.